﻿using System;
using System.Collections.Generic;
using System.Text;

using Koossery.MVCwin.Controller.itf;
using Koossery.MVCwin.Properties;
using Koossery.MVCwin.Util;

namespace Koossery.MVCwin.Filters.basefilter
{
	/// <author>Mohamadou Yacoubou</author>
	/// <summary>
	/// Base Class for all filters attribute
	/// </summary>
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
	public class FilterAttribute : Attribute
	{
		#region Fields

		/// <summary>
		/// The name of the action to execute. The default value is Execute
		/// </summary>
		private string actionName = Constants.Execute;

		/// <summary>
		/// The controller type to check
		/// </summary>
		private Type controllerType;

		/// <summary>
		/// View name to display. You should specify the controllerType or the ViewName not both of them
		/// </summary>
		private string viewName = null;

		#endregion Fields

		#region Public Properties

		public string ActionName
		{
			get { return actionName; }
			set
			{
			    if (string.IsNullOrEmpty(value)) throw new Exception(Resources.ArgumentNullException);
			    actionName = value;
			}
		}

		public Type ControllerType
		{
			get { return controllerType; }
			set
			{
			    if (value == null)
			    {
			        throw new ArgumentNullException(Resources.ArgumentNullException);
			    }
			    if (!typeof(IController).IsAssignableFrom(value))
			    {
			        throw new ArgumentException(String.Format(Resources.IncorrectControllerTypeException, value.FullName));
			    }

			    controllerType = value;
			}
		}

		public string ViewName
		{
			get { return viewName; }
			set { this.viewName = value; }
		}

		#endregion Public Properties
	}
}